package com.guozcc.bootweb.platform.config;

import org.redisson.Redisson;

import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    private static final String REDISSON_PREFIX = "redis://";
    @Value("${spring.redis.host}")
    private String redisHost;
    @Value("${spring.redis.port}")
    private String redisPort;

    private int timeout = 3000;
    private int connectionPoolSize = 64;
    private int connectionMinimumIdleSize=10;
    private int pingConnectionInterval = 60000;
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        // 1、创建配置
        Config config = new Config();
        config.useSingleServer()
                .setAddress(REDISSON_PREFIX+redisHost+":"+redisPort)
                .setTimeout(this.timeout)
                .setPingConnectionInterval(this.pingConnectionInterval)
                .setConnectionPoolSize(this.connectionPoolSize)
                .setConnectionMinimumIdleSize(this.connectionMinimumIdleSize);

        final RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;

//        config.useClusterServers(); 集群模式
//        config.useSentinelServers();哨兵模式
//        config.useMasterSlaveServers();主从模式



    }
}
